#pragma once
#include <vector>
#include "ostream"
namespace Date_module
{
    class Date
    {
        // friend std::ostream operator<<(std::ostream out, const Date& date);
        // 由于 cout 和 cin 不允许拷贝(单例) 所以 需要是引用类型
        // 友元函数声明 共有私有都无所谓
        friend std::ostream& operator<<(std::ostream& out, const Date& date);
        friend std::istream& operator>>(std::istream& in, Date& date);
    public:
        Date(int year = 1960, int month = 1, int day = 1);
        Date(const Date&);
        // Date operator=(const Date&);

        // Compare set
        bool operator>(const Date&) const;
        bool operator==(const Date&) const;
        bool operator<(const Date&) const;
        bool operator>=(const Date&) const;
        bool operator<=(const Date&) const;
        bool operator!=(const Date&) const;

        // Calculator
        Date& operator+=(int day_counting);
        Date operator+(int day_counting) const;
        Date operator++(int);
        Date& operator++();
        Date& operator--();
        Date operator--(int);
        Date operator-(int day_counting) const;
        Date& operator-=(int day_counting);
        int operator-(const Date& date) const;


    private:
        // auxiliary func
        inline int isleapyear(int year){
            return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ? 1 : 0;
        }
        inline int month2day(int year, int month)
        {
            using namespace std;
            static vector<int> month_day{-1,31,30,31,30,31,30,31,31,30,31,30,31};
            if(month == 2)
            {
                return 28 + isleapyear(year);
            }
            else return month_day[month];
        }
    private:
        int _day;
        int _month;
        int _year;
    };
}